#include "Data.h"
#include "common.h"


CData::CData()
{
}

CData::~CData()
{
}

int CData::Sendn(int nSocket , const void *pStr , unsigned int nLen)
{
	int n = nLen , nRet;
	char *str = (char*)pStr;
	while(n > 0)
	{
		nRet = send(nSocket , str , n , MSG_NOSIGNAL);
		if(nRet <= 0)
		{
			if(errno == EINTR || errno == EAGAIN)
			{
				continue;
			}
			debug_output("Error Send Msg Failed ...... Error = %d, Socket = %d\n", errno, nSocket);
			return nRet;
		}
		n -= nRet;
		str += nRet;
	}
	return (nLen - n);
}

int CData::Recvn(int nSocket , void *pStr , unsigned int nLen)
{
	int n = nLen;
	char *str = (char*)pStr;

	int nRet;
	while(1)
	{
		nRet = recv(nSocket , str , n , MSG_NOSIGNAL);
		if(nRet <= 0)
		{
			if(errno == EINTR || errno == EAGAIN)
			{
				continue;
			}
			debug_output("Error Recv Msg Failed ...... Errno = %d, Socket = %d\n", errno, nSocket);
			break;
		}
		break;
	}
	return nRet;
}
